/**
 * Copyright (C) 2017-2018 pinganfang, Inc. All Rights Reserved.
 */
package com.pingan.haofang.searchcloud.api.search.validator;

import java.util.Objects;

import org.springframework.stereotype.Component;

import com.pingan.haofang.framework.common.functional.lang.control.validator.bo.ValidationError;
import com.pingan.haofang.framework.common.functional.lang.control.validator.bo.ValidationResult;
import com.pingan.haofang.searchcloud.api.search.form.SqlForm;
import com.pingan.haofang.searchcloud.common.validator.annotation.ValidHandler;

/**
 * @author huhailiang937
 * @date 2017年5月10日下午2:09:36
 * @since 1.0.0
 */
@Component
public class SqlFormValidator {

    @ValidHandler
    public void select(ValidationResult result, SqlForm form) {
        String sql = form.getSql();
        if(Objects.isNull(sql)){
            result.addError(ValidationError.of("SqlForm.sql", "search.sql.illegal")
                    .invalidValue(sql));
        }
        return;
    }
    
    
    @ValidHandler
    public void postSelect(ValidationResult result, SqlForm form) {
        select(result,form);
    }
}


